package com.shenzhenai.composebasic.components

import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.Image
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview

/**
 * @author huangzehui
 * @date 2025/9/12 13:46 周五
 * @description
 *
 * TextField 用法
 * https://www.bilibili.com/video/BV1E44y1n7pk?vd_source=e07cc8cc94eb22bd76722071b03cd199&spm_id_from=333.788.player.switch
 *
 */
@Composable
fun TextFieldSample() {
    var value by remember {
        mutableStateOf("")
    }

    TextField(
        value = value, onValueChange = {
            value = it
        }, label = {
            Text("姓名")
        },
        placeholder = {
            Text("请在这里输入姓名")
        },
        leadingIcon = {
            // 输入框左边的icon
            Icon(imageVector = Icons.Default.AccountBox, contentDescription = null)
        },
        trailingIcon = {
            // 输入框右边的icon
            Icon(imageVector = Icons.Default.Image, contentDescription = null)
        },
        keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done, keyboardType = KeyboardType.Number),
        keyboardActions = KeyboardActions(
            onDone = {


            }
        ),
        singleLine = true
    )

}

@Preview
@Composable
fun TextFieldSamplePreview() {
    TextFieldSample()
}